<template>
  <div class="search">
    <Card>
      <Row @keydown.enter.native="handleSearch">
        <Form
          ref="searchForm"
          :model="searchForm"
          inline
          :label-width="75"
          class="search-form"
        >
          <Form-item label="提现申请人" prop="withdrawalBy">
            <Input
              type="text"
              v-model="searchForm.withdrawalBy"
              placeholder="请输入申请人名称"
              clearable
              style="width: 200px"
            />
          </Form-item>
          <Form-item label="审核日期" prop="applicationDate">
            <DatePicker
              v-model="selectDate"
              type="datetimerange"
              format="yyyy-MM-dd HH:mm:ss"
              clearable
              @on-change="selectDateRange"
              placeholder="选择起始时间"
              style="width: 200px"
            ></DatePicker>
          </Form-item>
          <Button
            @click="handleSearch"
            class="search-btn"
            type="primary"
            icon="ios-search"
            >搜索</Button
          >
        </Form>
      </Row>
      <Table
        :loading="loading"
        border
        :columns="columns"
        class="mt_10"
        :data="data"
        ref="table"
      ></Table>
      <Row type="flex" justify="end" class="mt_10">
        <Page
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50, 100]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
    </Card>
    <!-- 审核 -->
    <Modal
      v-model="detailFlag"
      title="审核"
      @on-ok="handleSubmit"
      @on-cancel="handleCancel"
    >
      <div>
        <Form ref="form" :model="form" :label-width="100">
          <FormItem label="打款否" prop="auditStatus">
            <i-switch size="large" v-model="form.auditStatus">
              <span slot="open">已打</span>
              <span slot="close">未打</span>
            </i-switch>
          </FormItem>
         <FormItem
            label="未打原因"
            v-show="!form.auditStatus"
            prop="categoryId"
          >
            <Input
              v-model="form.auditRemark"
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 5 }"
            />
          </FormItem> 
        </Form>
      </div>
    </Modal>
  </div>
</template>

<script>
import { paymentGetList, updatePayment} from "@/api/recycling.js";

export default {
  name: "payment",
  
  data() {
    return {
      loading: true, // 表单加载状态
      detailFlag: false,
      selectDate: [],
      searchForm: {
        // 请求参数
        pageNumber: 1,
        pageSize: 10,
        order: "desc",
        withdrawalBy: "",
        applicationDateStart: "",
        applicationDateEnd: "",
		auditStatus:"tg"
      },
      form: {
        auditStatus: true,
        auditRemark: "",
      },
      EditObj: null,
      columns: [
        {
          title: "提现申请人",
          key: "withdrawalBy",
          tooltip: true,
        },
        {
          title: "提现金额",
          key: "withdrawalAmount",
        },
        {
          title: "申请日期",
          key: "applicationDate",
        },

        {
          title: "审核时间",
          align: "left",
          key: "auditTime",
        },
        {
          title: "打款状态",
          align: "left",
          render: (h, params) => {
            return h(
              "div",
              {},
              params.row.withdrawalStatus == "ytx"
                ? "已打款"
                : params.row.withdrawalStatus == "wtx"
                ? "未打款"
                : ""
            );
          },
        },
        // {
        //   title: "打款状态",
        //   align: "left",
        //   render: (h, params) => {
        //     return h(
        //       "div",
        //       {},
        //       params.row.withdrawalStatus == "ytx"
        //         ? "已打款"
        //         : params.row.withdrawalStatus == "wtx"
        //         ? "未打款"
        //         : ""
        //     );
        //   },
        // },
        {
          title: "未打款原因",
          align: "left",
          key: "withdrawalRemark",
        },
        {
          title: "备注",
          align: "left",
          key: "remark",
        },
        {
          title: "操作",
          key: "action",
          align: "center",
          width: 200,
          fixed: "right",
          render: (h, params) => {
            return h(
              "div",
              {
                style: {
                  display: "flex",
                  justifyContent: "center",
                },
              },
              [
                h(
                  "Button",
                  {
                    props: {
                      type: "info",
                      size: "small",
                    },
                    style: {
                      marginRight: "5px",
                      display: params.row.withdrawalStatus=='ytx' ? "none" : "block",
                    },
                    on: {
                      click: () => {
                        this.detail(params.row);
                      },
                    },
                  },
                  "是否打款"
                ),
              ]
            );
          },
        },
      ],
      data: [], // 表单数据
      total: 0, // 表单数据总数
    };
  },
  methods: {
    // 起止时间从新赋值
    selectDateRange(v) {
      if (v) {
        this.searchForm.applicationDateStart = v[0];
        this.searchForm.applicationDateEnd = v[1];
      }
    },
    // 分页 改变页码
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getData();
    },
    // 分页 改变页数
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.searchForm.pageNumber = 1;
      this.getData();
    },
    // 搜索
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.getData();
    },
    //查询会员列表
    getData() {
      paymentGetList(this.searchForm).then((res) => {
        if (res.result.records) {
          this.loading = false;
          this.data = res.result.records;
          this.total = res.result.total;
        }
      });
    },
    //查看会员
    detail(row) {
      this.detailFlag = true;
      this.EditObj = { ...row };
      // this.$router.push({ name: "member-detail", query: { id: row.id } });
    },
    // 审批提交事件
    handleSubmit() {
      updatePayment({
        withdrawalStatus: this.form.auditStatus ? "ytx" : "wtx",
        withdrawalRemark: this.form.auditRemark,
        id: this.EditObj.id,
      }).then((res) => {
        if (res.code == 200) {
          this.$Message.success("修改成功！");
          this.form = {
            auditStatus: true,
            auditRemark: "",
          };
          this.EditObj = {};
          this.$refs.form.resetFields();
          this.getData();
        } else {
          this.$Message.error("修改失败！");
        }
      });
    },
    // 审批取消事件
    handleCancel() {
      this.form = {
        auditStatus: true,
        auditRemark: "",
      };
      this.$refs.form.resetFields();
    },
  },
  mounted() {
    this.getData();
  },
};
</script>
<style lang="scss" scoped>
/deep/ .ivu-table-wrapper {
  width: 100%;
}
/deep/ .ivu-card {
  width: 100%;
}
.face {
  width: 60px;
  height: 60px;
  border-radius: 50%;
}
</style>
